//
//  AesDecryptor.h
//  aestest
//
//  Created by yaoziyang on 14-7-16.
//  Copyright (c) 2014年 yaoziyang. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CommonCrypto/CommonHMAC.h>
#import <CommonCrypto/CommonCryptor.h>
#import <CommonCrypto/CommonDigest.h>

@interface Decryptor : NSObject

/*
 * Desc: input encrypted byte stream, decrypt 16*n bytes of data,
 *       the rest will be keeped and decrypted until next time call 'accept' or 'doFinal'.
 * Return: the decrypted bytes, may be nil or zero length.
 */
- (NSData*)accept:(const void *)dataIn inDataLen:(size_t) dataInLength;

/*
 * Desc: decrypt rested bytes.
 */
- (NSData*)doFinal;

@property(nonatomic, readonly, assign) CCOptions paddingOptions;
@property(nonatomic, readonly, assign) CCAlgorithm algorithm;
@property(nonatomic, readonly, retain) NSData* key;

@end

/*
 * Note: not tested!
 */
@interface Aes128Decryptor : Decryptor

- (NSData*)accept:(const void *)dataIn inDataLen:(size_t) dataInLength;
- (NSData*)doFinal;

/*
 * Desc: create aes-128-ecb decryptor.
 * Note: key lenght must be 16, 24, or 32, otherwise return nil.
 */
+ (id)create:(NSData*)key;

/*
 * Desc: create aes decryptor.
 * Note: key lenght must be 16, 24, or 32, otherwise return nil.
 */
+ (id)create:(CCAlgorithm)alg padding:(CCOptions)padOptions key:(NSData*)key;

@end
